const validator = require('validator')

const isString = value => (typeof value === 'string')

const isEmail = value => isString(value) && validator.isEmail(value)

const isPassword = value => isString(value) && value.length >= 8

const isDeviceType = value => isString(value) && ['web', 'ios', 'android'].indexOf(value) !== -1

const isAppType = value => isString(value) && ['admin', 'merchant', 'client'].indexOf(value) !== -1

const isBoolean = value => (typeof value === 'boolean' || value === 1 || value === 0)

const isUInt = value => /^\d+$/.test(value)

const isISO8601Date = value => isString(value) && validator.isISO8601(value)

const isURL = value => isString(value) && validator.isURL(value)

const isDecimal = value => /^\d+(.\d+)?$/.test(value)

const isMerchantOrganisationRoleType = value => isString(value) && ['admin', 'staff'].indexOf(value) !== -1

const isUtilityTokenType = value => isString(value) && ['reset_password', 'provider_invite', 'provider_organisation_invite'].indexOf(value) !== -1

const isCampaignStatusType = value => isString(value) && ['draft', 'in_progress', 'finished', 'paused', 'cancelled'].indexOf(value) !== -1

const isCurrencyType = value => isString(value) && ['hkd', 'usd', 'cny'].indexOf(value) !== -1

const isIndustryType = value => isString(value) && ['professional', 'influencer'].indexOf(value) !== -1

const isUserPaymentMethod = value => isString(value) && ['paypal'].indexOf(value) !== -1

const isUserPaymentStatus = value => isString(value) && ['pending', 'paid', 'rejected'].indexOf(value) !== -1

const isApplicationStatus = value => isString(value) && ['user_pending', 'user_accepted', 'user_completed', 'user_cancelled', 'system_paused', 'others'].indexOf(value) !== -1

const isApplicationApplyMethod = value => isString(value) && ['invitation', 'self_apply'].indexOf(value) !== -1

const isApplicationTaskStatus = value => isString(value) && ['pending', 'in_review', 'accepted'].indexOf(value) !== -1

module.exports = {
  isString,
  isEmail,
  isPassword,
  isDeviceType,
  isAppType,
  isBoolean,
  isUInt,
  isISO8601Date,
  isURL,
  isDecimal,
  isMerchantOrganisationRoleType,
  isUtilityTokenType,
  isCampaignStatusType,
  isCurrencyType,
  isIndustryType,
  isUserPaymentMethod,
  isUserPaymentStatus,
  isApplicationStatus,
  isApplicationApplyMethod,
  isApplicationTaskStatus,
}
